Problem Description

Binary Search TreesRecap

Your task is to implement a Binary Search Tree supporting four key operations.

  • The number of operations is $N$, where $1 \le N \le 2 \cdot 10^5$.
  • ins k: Insert an integer key $k$ into the BST. If $k$ already exists, this operation does nothing.
  • find k: Search for key $k$. Output 'true' if it exists, otherwise 'false'.
  • succ k: Find the successor of $k$—the smallest key in the tree that is strictly greater than $k$. Output 'null' if none exists.
  • pred k: Find the predecessor of $k$—the largest key in the tree that is strictly smaller than $k$. Output 'null' if none exists.
  • Key Assumption: For successor and predecessor queries, the key $k$ is guaranteed to be present in the tree.